package com.ruoyi.web.controller.counter;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.counter.domain.Records;
import com.ruoyi.counter.service.IRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 器具使用记录Controller
 *
 * @author xll
 * @date 2021-07-29
 */
@RestController
@RequestMapping("/records/records")
public class RecordsController extends BaseController
{
    @Autowired
    private IRecordsService recordsService;

    /**
     * 查询器具使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('records:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(Records records )
    {

        startPage();
        List<Records> list = recordsService.selectRecordsList(records);
        return getDataTable(list);
    }

    /**
     * 导出器具使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('records:records:export')")
    @Log(title = "器具使用记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Records records)
    {
        List<Records> list = recordsService.selectRecordsList(records);
        ExcelUtil<Records> util = new ExcelUtil<Records>(Records.class);
        return util.exportExcel(list, "器具使用记录数据");
    }

    /**
     * 获取器具使用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('records:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(recordsService.selectRecordsById(id));
    }

    /**
     * 新增器具使用记录
     */
    @PreAuthorize("@ss.hasPermi('records:records:add')")
    @Log(title = "器具使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Records records)
    {
        return toAjax(recordsService.insertRecords(records));
    }

    /**
     * 修改器具使用记录
     */
    @PreAuthorize("@ss.hasPermi('records:records:edit')")
    @Log(title = "器具使用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Records records)
    {
        return toAjax(recordsService.updateRecords(records));
    }

    /**
     * 删除器具使用记录
     */
    @PreAuthorize("@ss.hasPermi('records:records:remove')")
    @Log(title = "器具使用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recordsService.deleteRecordsByIds(ids));
    }
}
